import navSkin from "../../../common/navSkin"

export default {
	addressConfirm(address) {

		this.formData.province = address[0].id;
		this.formData.city = address[1].id;
		this.formData.area = address[2].id;
		this.formData.address =
			`${address[0].name ||''}${address[1].name ||''}${address[2].name}`
	},

	getPageData() {
		let that = this
		that.$httpRequest.request({
			that,
			url: 'wechat/getAddressDetail',
			method: 'get',
			params: {
				id: that.id
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (res.data) {
						that.formData = res.data
					}


				} else {

				}
			}
		})
	},
	submit() {
		let that = this
		let params = {}
		if (this.id) {
			params = this.formData
			params.id = this.id
		} else {
			params = this.formData
		}
		console.log(params)
		that.$httpRequest.request({
			that,
			url: that.id ? 'wechat/editAddress' : 'wechat/addAddress',
			method: 'post',
			params,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$navSkin.goBack();
				} else {

				}
			}
		})
	},
}